<template>
  <div class="app-container">
  <el-card class="box-card" shadow="never" style="border:0px;">
      <div slot="header" style="color:#303133;font-size:14px;font-weight:bold;">
        <span>已处理任务</span>
      </div>
    <div class="filter-container" id="searchBox">
      <div class="left">
        <el-form :inline="true" :model="listQuery" class="demo-form-inline" size="medium" label-position="right" ref="listQuery">
          <el-form-item label="姓名：" prop="realName">
            <el-input v-model="listQuery.realName" clearable class="filter-item" placeholder="请输入借款人姓名"/>
          </el-form-item>
          <el-form-item label="手机号：" prop="mobile">
            <el-input v-model="listQuery.mobile" clearable class="filter-item" placeholder="请输入借款人手机号" />
          </el-form-item>
          <el-form-item label="身份证号：" prop="idCardNo">
            <el-input v-model="listQuery.idCardNo" clearable class="filter-item" placeholder="请输入借款人身份证号" />
          </el-form-item>
          <el-form-item label="进件时间：" prop="createTaskDate">
            <el-date-picker
              class="date_item"
              v-model="listQuery.createTaskDate"
              type="daterange"
              range-separator="至"
              align="right"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="贷款类型" prop="loanType">
            <el-select v-model="listQuery.loanType" placeholder="请选择" style="min-width:100%;" @change="getLoanType">
              <el-option
                v-for="item in loanTypes"
                :key="item.dictValue"
                :label="item.dictName"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目状态" prop="projectStatus">
            <el-select v-model="listQuery.projectStatus" placeholder="请选择" style="min-width:100%;" @change="getList">
              <el-option
                v-for="item in projectStatusArr"
                :key="item.dictValue"
                :label="item.dictName"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="right">
        <el-button type="primary"  @click="getList(listQuery)">查询</el-button>
        <el-button  @click="restForm('listQuery')">重置</el-button>
        <el-button  type="text" @click="closeSearch">{{showOperation}}<i :class="[!showAll? 'el-icon-caret-bottom' : 'el-icon-caret-top']"></i>
               </el-button>
      </div>
    </div>

    <vxe-toolbar ref="xToolbar">
         <template #buttons>
        </template>
    </vxe-toolbar>
    <vxe-table
      v-loading="loading"
      :data="taskData"
      border="none"
      highlight-hover-row
      show-header-overflow
      show-overflow
      align="center"
      :header-cell-style="{ background: '#F7F7F8', color: '#606266' }"
      @cell-dblclick="cellDblclick"
    >
      <vxe-table-column type="seq" title="序号" min-width="50"/>
      <vxe-table-column title="客户姓名" field="realName" min-width="120"/>
      <vxe-table-column title="身份证号" field="idCardNo" min-width="180"/>
      <vxe-table-column title="手机号" field="mobile" min-width="120"/>
      <vxe-table-column title="资方" field="capitalName" min-width="120"/>
      <vxe-table-column title="产品名称" field="productName" min-width="120"/>
      <vxe-table-column title="抵押类型" field="pledgeTypeName" min-width="120"/>
      <vxe-table-column title="借贷金额(万)" field="applyAmount" min-width="120">
        <template v-slot="{row}">{{row.applyAmount}}</template>
      </vxe-table-column>
      <vxe-table-column title="借贷期限(期)" field="applyTermName" min-width="120">
        <template v-slot="{row}">{{row.applyTermName}}</template>
      </vxe-table-column>
      <vxe-table-column title="创建时间" field="projectCreateTime" min-width="150"/>
      <vxe-table-column title="贷款类型" field="loanTypeName" min-width="185"/>
      <vxe-table-column title="任务节点名称" field="taskNodeName" min-width="185"/>
      <vxe-table-column title="客户经理" field="creatorName" min-width="150"/>
      <vxe-table-column title="项目状态" field="projectStatusName" min-width="150"/>
      <vxe-table-column title="项目id" field="projectId" min-width="180"/>
      <vxe-table-column title="操作" fixed="right" min-width="150">
        <template v-slot="{ row }">
          <span v-if="row.projectStatus === 90 && row.loanType === 1">
            <el-button type="text" @click="getTask(row,2)">请款结果</el-button>
          </span>
          <span v-else>
            <el-button type="text" round @click="getTask(row,1)">查看</el-button>
          </span>
<!--          <span v-if="row.projectStatus === 90">-->
<!--            <el-button type="text" @click="getTask(row,2)">请款结果</el-button>-->
<!--          </span>-->
<!--          <span v-else>-->
<!--            <el-button type="text" round @click="getTask(row,1)">查看</el-button>-->
<!--          </span>-->
        </template>
      </vxe-table-column>
    </vxe-table>
  </el-card>
    <vxe-pager
      class="pager"
      @page-change="changePage"
      :current-page.sync="listQuery.pageNo"
      :page-size.sync="listQuery.pageSize"
      :total="total"
      :page-sizes="[10, 30,50, 100]"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
    >
    </vxe-pager>
  </div>
</template>

<script>
import { listTasks, receiveTask } from '@/api/project';
import { findByDictTypeName } from '@/api/dict';
import DicSelect from '@/components/select/index';
import { mapGetters } from 'vuex'
import {getProcessKey} from '@/utils/index'
export default {
  name: 'User',
  components: { DicSelect },
  data: function () {
    return {
      active: 0,
      taskData: [],
      total: 0,
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        realName: undefined,
        mobile: undefined,
        idCardNo: undefined,
        pledgeType: undefined,
        projectStatus: undefined,
        startTime: undefined,
        endTime: undefined,
        taskId: undefined,
        createTaskDate: undefined,
        taskStatus: 0
        // taskType: undefined,
      },
      showAll:true,
      loanTypes:undefined,
      projectStatusArr:undefined,
      loading: true
    };
  },
  computed: {
    ...mapGetters(['processKey']),
    showOperation: function() {
   if (this.showAll == false) {
    //对文字进行处理
    return "展开";
   } else {
    return "收起";
   }
  }
  },
  mounted(){
  /**
   * 收起搜索
   */
  this.$nextTick(function() {
  //  this.closeSearch();
  });
  },
  created: function () {
    this.getList();
    this.findByDictTypeName('项目贷款类型');
  },
  methods: {
    closeSearch() {
       this.showAll = !this.showAll;
       var searchBoxHeght = document.getElementById("searchBox");
       if (this.showAll == false) {
        searchBoxHeght.style.height = 50 + "px";
       } else {
        searchBoxHeght.style.height = "auto";
       }
    },

    findByDictTypeName(dictTypeName) {
      findByDictTypeName(dictTypeName).then((data) => {
        this.loanTypes = data.data;
      });
    },

    // 按照贷款类型查询不同的项目状态
    getLoanType(val) {
      var dictTypeName = null;
      if (val == 1){
        dictTypeName = '项目状态';
      }
      if (val == 2){
        dictTypeName = '信用贷项目状态';
      }
      this.listQuery.projectStatus = undefined;
      findByDictTypeName(dictTypeName).then((data) => {
        this.projectStatusArr = data.data;
      });
      this.getList();
      return false;
    },

    // 列表查询
    getList() {
    console.log(this.listQuery.createTaskDate)
      this.loading = true;
      this.taskId = this.$route.query.taskId;
      listTasks(this.listQuery).then((data) => {
        this.taskData = data.data;
        this.total = data.total;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    receiveTask(row) {
      this.$confirm('确定要开始吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 开始提交信息
        receiveTask(row.id).then((data) => {
          this.$router.push({
            path: '/detail/deal',
            query: { projectId: row.projectId, taskId: row.id, projectStatus: row.projectStatus,
             appointNextTime: row.appointNextTime,ifReceive: row.ifReceive },
          });
        });
      });
    },

    getTask(row,indexType) {
      if (row.loanType == 1){
        let processKey = getProcessKey(row.processKey)
        if(processKey == "dg") {
          this.$router.push({ path: '/detail/deal_dg' ,
            query: { projectId: row.projectId, taskId: row.id, projectStatus: row.projectStatus,
              appointNextTime: row.appointNextTime,taskStatus: row.taskStatus,operationLook: true,activeIndex: indexType === 1 ? "1": "90",realName:row.realName  },
          })
        }else{
          this.$router.push({ path: '/detail/deal' ,
            query: { projectId: row.projectId, taskId: row.id, projectStatus: row.projectStatus,
              appointNextTime: row.appointNextTime,taskStatus: row.taskStatus,operationLook: true,activeIndex: indexType === 1 ? "1": "90",realName:row.realName  },
          })
        }
      }
      /*信用贷详情页面跳转*/
      if (row.loanType == 2){
        this.$router.push({ path: '/task/deal_credit',
          query: { projectId: row.projectId, taskId: row.id, projectStatus: row.taskNodeProjectStatus,taskStatus: row.taskStatus,realName:row.realName,isNeedSubmit:false},
        })
      }
    },
    changePage() {
      this.getList();
    },
    restForm(formName) {
      this.$refs[formName].resetFields();
      this.listQuery.createTaskDate = undefined;
      this.projectStatusArr = undefined;
      this.getList();
    },
    cellDblclick({row,rowIndex,column,columnIndex,cell},event) {
      let _this = this;
      this.$copyText(event.target.innerText).then(function() {
        _this.$message.info('复制成功');
      });
    }
  },

};
</script>

<style lang="css" scoped>
.filter-container {
  display: flex;
  justify-content: space-between;
}


.pager{
  position: fixed;
  bottom: 0;
  right: 28px;
  background-color: #FAFAFB;
  z-index: 2;
  height: 40px;
  width: calc(100% - 260px);
  }

.right >>> .el-button--primary,.el-button--default {
  padding: 10px 20px;
}
.vxe-table--render-default >>> .el-button--text{
  color: #2b7bfb;
}
.app-container >>> .vxe-table--render-default,.vxe-pager {
  font-family: PingFangSC, Arial, Helvetica, sans-serif;
}

.left {
  flex: 14;
  display: flex;
  flex-flow: row wrap;
  margin-right: 20px;
}
.left >>> .el-form {
  width: 100%;
}
.left >>> .el-form .el-form-item {
  display: flex;
  flex-flow: row nowrap;
  width: 30%;
  margin-right: 3%;
  float: left;
  margin-bottom: 14px;
}

.left >>> .el-form .el-form-item .el-form-item__label {
  font-weight: 500;
  color: #606266;
  text-align: left;
  /* flex: 1; */
}

.left >>> .el-form .el-form-item .el-form-item__content {
  flex: 1;
  /*超出部分隐藏*/
  text-overflow: ellipsis;
  /* 超出部分显示省略号 */
  white-space: nowrap;
  /*规定段落中的文本不进行换行 */
  width: 100%;
}
.date_item {
  width: 100%;
}
.right {
  flex: 2;
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-end;
  margin-right: 30px;
  /* margin-bottom: 30px; */
}
</style>
